package com.jikedaquan.game.jwt.util;

import cn.hutool.core.convert.Convert;
import com.jikedaquan.game.jwt.pojo.ValueInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * 游戏数值计算工具，包含升级所需经验，修炼获得经验，比武获得经验
 */
public class ValueCalc {
    /**
     * 通过缓存的方式提高获取值效率
     */
    private static Map<Integer, ValueInfo> levelValues = new HashMap<Integer, ValueInfo>();
    static {
        levelValues.put(1,new ValueInfo(1,20,20,20,50));
        levelValues.put(2,new ValueInfo(2,21,21,21,51));
        levelValues.put(3,new ValueInfo(3,36,29,22,52));
        levelValues.put(4,new ValueInfo(4,101,57,23,54));
        levelValues.put(5,new ValueInfo(5,276,117,25,56));
        levelValues.put(6,new ValueInfo(6,645,222,26,58));
        levelValues.put(7,new ValueInfo(7,1316,389,28,60));
        levelValues.put(8,new ValueInfo(8,2421,634,30,62));
        levelValues.put(9,new ValueInfo(9,4116,975,32,64));
        levelValues.put(10,new ValueInfo(10,6581,1429,33,67));
        levelValues.put(11,new ValueInfo(11,10020,2015,35,69));
        levelValues.put(12,new ValueInfo(12,14661,2752,37,72));
        levelValues.put(13,new ValueInfo(13,20756,3661,39,75));
        levelValues.put(14,new ValueInfo(14,28581,4762,41,78));
        levelValues.put(15,new ValueInfo(15,38436,6076,43,80));
        levelValues.put(16,new ValueInfo(16,50645,7625,45,83));
        levelValues.put(17,new ValueInfo(17,65556,9430,47,86));
        levelValues.put(18,new ValueInfo(18,83541,11514,49,89));
        levelValues.put(19,new ValueInfo(19,104996,13900,52,92));
        levelValues.put(20,new ValueInfo(20,130341,16611,54,95));
        levelValues.put(21,new ValueInfo(21,160020,19671,56,99));
        levelValues.put(22,new ValueInfo(22,194501,23104,58,102));
        levelValues.put(23,new ValueInfo(23,234276,26935,60,105));
        levelValues.put(24,new ValueInfo(24,279861,31187,63,108));
        levelValues.put(25,new ValueInfo(25,331796,35887,65,112));
        levelValues.put(26,new ValueInfo(26,390645,41059,67,115));
        levelValues.put(27,new ValueInfo(27,456996,46730,69,119));
        levelValues.put(28,new ValueInfo(28,531461,52925,72,122));
        levelValues.put(29,new ValueInfo(29,614676,59671,74,126));
        levelValues.put(30,new ValueInfo(30,707301,66995,76,129));
        levelValues.put(31,new ValueInfo(31,810020,74923,79,133));
        levelValues.put(32,new ValueInfo(32,923541,83482,81,136));
        levelValues.put(33,new ValueInfo(33,1048596,92701,84,140));
        levelValues.put(34,new ValueInfo(34,1185941,102607,86,144));
        levelValues.put(35,new ValueInfo(35,1336356,113228,88,147));
        levelValues.put(36,new ValueInfo(36,1500645,124593,91,151));
        levelValues.put(37,new ValueInfo(37,1679636,136729,93,155));
        levelValues.put(38,new ValueInfo(38,1874181,149666,96,159));
        levelValues.put(39,new ValueInfo(39,2085156,163432,98,163));
        levelValues.put(40,new ValueInfo(40,2313461,178058,101,167));
        levelValues.put(41,new ValueInfo(41,2560020,193572,103,170));
        levelValues.put(42,new ValueInfo(42,2825781,210004,106,174));
        levelValues.put(43,new ValueInfo(43,3111716,227384,108,178));
        levelValues.put(44,new ValueInfo(44,3418821,245743,111,182));
        levelValues.put(45,new ValueInfo(45,3748116,265110,113,186));
        levelValues.put(46,new ValueInfo(46,4100645,285516,116,190));
        levelValues.put(47,new ValueInfo(47,4477476,306993,118,195));
        levelValues.put(48,new ValueInfo(48,4879701,329571,121,199));
        levelValues.put(49,new ValueInfo(49,5308436,353281,124,203));
        levelValues.put(50,new ValueInfo(50,5764821,378155,126,207));
        levelValues.put(51,new ValueInfo(51,6250020,404224,129,211));
        levelValues.put(52,new ValueInfo(52,6765221,431520,131,215));
        levelValues.put(53,new ValueInfo(53,7311636,460076,134,220));
        levelValues.put(54,new ValueInfo(54,7890501,489923,137,224));
        levelValues.put(55,new ValueInfo(55,8503076,521094,139,228));
        levelValues.put(56,new ValueInfo(56,9150645,553621,142,233));
        levelValues.put(57,new ValueInfo(57,9834516,587537,145,237));
        levelValues.put(58,new ValueInfo(58,10556021,622875,147,241));
        levelValues.put(59,new ValueInfo(59,11316516,659668,150,246));
        levelValues.put(60,new ValueInfo(60,12117381,697949,153,250));
        levelValues.put(61,new ValueInfo(61,12960020,737752,156,254));
        levelValues.put(62,new ValueInfo(62,13845861,779111,158,259));
        levelValues.put(63,new ValueInfo(63,14776356,822059,161,263));
        levelValues.put(64,new ValueInfo(64,15752981,866630,164,268));
        levelValues.put(65,new ValueInfo(65,16777236,912858,167,272));
        levelValues.put(66,new ValueInfo(66,17850645,960778,169,277));
        levelValues.put(67,new ValueInfo(67,18974756,1010423,172,281));
        levelValues.put(68,new ValueInfo(68,20151141,1061830,175,286));
        levelValues.put(69,new ValueInfo(69,21381396,1115031,178,291));
        levelValues.put(70,new ValueInfo(70,22667141,1170063,180,295));
        levelValues.put(71,new ValueInfo(71,24010020,1226960,183,300));
        levelValues.put(72,new ValueInfo(72,25411701,1285758,186,305));
        levelValues.put(73,new ValueInfo(73,26873876,1346491,189,309));
        levelValues.put(74,new ValueInfo(74,28398261,1409196,192,314));
        levelValues.put(75,new ValueInfo(75,29986596,1473908,195,319));
        levelValues.put(76,new ValueInfo(76,31640645,1540663,197,323));
        levelValues.put(77,new ValueInfo(77,33362196,1609497,200,328));
        levelValues.put(78,new ValueInfo(78,35153061,1680446,203,333));
        levelValues.put(79,new ValueInfo(79,37015076,1753545,206,338));
        levelValues.put(80,new ValueInfo(80,38950101,1828833,209,343));
        levelValues.put(81,new ValueInfo(81,40960020,1906345,212,347));
        levelValues.put(82,new ValueInfo(82,43046741,1986117,215,352));
        levelValues.put(83,new ValueInfo(83,45212196,2068187,217,357));
        levelValues.put(84,new ValueInfo(84,47458341,2152592,220,362));
        levelValues.put(85,new ValueInfo(85,49787156,2239368,223,367));
        levelValues.put(86,new ValueInfo(86,52200645,2328553,226,372));
        levelValues.put(87,new ValueInfo(87,54700836,2420184,229,377));
        levelValues.put(88,new ValueInfo(88,57289781,2514299,232,382));
        levelValues.put(89,new ValueInfo(89,59969556,2610935,235,387));
        levelValues.put(90,new ValueInfo(90,62742261,2710130,238,392));
        levelValues.put(91,new ValueInfo(91,65610020,2811922,241,397));
        levelValues.put(92,new ValueInfo(92,68574981,2916349,244,402));
        levelValues.put(93,new ValueInfo(93,71639316,3023449,247,407));
        levelValues.put(94,new ValueInfo(94,74805221,3133260,250,412));
        levelValues.put(95,new ValueInfo(95,78074916,3245821,253,417));
        levelValues.put(96,new ValueInfo(96,81450645,3361170,256,422));
        levelValues.put(97,new ValueInfo(97,84934676,3479345,259,427));
        levelValues.put(98,new ValueInfo(98,88529301,3600386,262,432));
        levelValues.put(99,new ValueInfo(99,92236836,3724331,265,437));
        levelValues.put(100,new ValueInfo(100,96059621,3851220,268,442));
    }
    /**
     * 根据修炼时长和等级计算出应得经验
     * @param level 等级
     * @param minute 分钟
     * @param excited 兴奋度，越低，获得收益越少
     * @return 经验
     */
    public static Integer exerciseExp(int level, int minute, int excited){
        if (level<0||level>99||excited<0||excited>100||minute<0){
            return null;
        }
        long exerciseExp = levelValues.get(level).getExerciseExp();
        exerciseExp = Math.round(exerciseExp*minute/240.0 * excited / 100.0);
        return Convert.toInt(exerciseExp);
    }

    /**
     * 根据当前等级获取下一级所需经验
     * @param level 当前等级
     * @return
     */
    public static Integer upgradeExp(int level){
        if (level<0||level>99){
            return null;
        }
        return levelValues.get(level+1).getExp();
    }

    /**
     * 比武过程中获得的经验
     * @param level 等级
     * @param excited 兴奋度，越低，获得收益越少
     * @return
     */
    public static Integer pkExp(int level,int excited){
        if (level<0||level>99||excited<0||excited>100){
            return null;
        }
        long pkExp = levelValues.get(level).getPkExp();
        pkExp = Math.round(pkExp * excited / 100.0);
        return Convert.toInt(pkExp);
    }

    /**
     * 比武过程中获得的金币
     * @param level 等级
     * @param excited 兴奋度
     * @return
     */
    public static Integer pkMoney(int level,int excited){
        if (level<0||level>99||excited<0||excited>100){
            return null;
        }
        long pkMoney = levelValues.get(level).getPkMoney();
        pkMoney = Math.round(pkMoney * excited / 100.0);
        return Convert.toInt(pkMoney);
    }

    public static void main(String[] args) {
        //初始值生成
        for (int i = 1; i <= 100; i++) {
            int exp = Convert.toInt(Math.pow(i-1,4)+20);
            int exerciseExp = Convert.toInt(Math.floor(Math.pow(i-1,3.3)+20));
            int pkExp = Convert.toInt(Math.floor(Math.pow(i-1,1.2)+20));
            int pkMoney = Convert.toInt(Math.floor(Math.pow(i-1,1.3)+50));
            System.out.println(String.format("levelValues.put(%d,new ValueInfo(%d,%d,%d,%d,%d));",i,i,exp,exerciseExp,pkExp,pkMoney));
        }
       /* //Test pkExp
        System.out.println(pkExp(1,23));
        //Test pkMoney
        System.out.println(pkMoney(1,88));
        //Test upgradeExp
        System.out.println(upgradeExp(0));
        //Test exerciseExp
        System.out.println(exerciseExp(1,240,99));*/
    }
}
